package ru.papergames.controller.commands
{
	import mx.utils.URLUtil;
	import org.puremvc.as3.interfaces.INotification;
	import ru.papergames.controller.commands.BaseCommand;
	import ru.papergames.controller.notifications.CoreNotifications;
	import ru.papergames.view.mediators.MainApplicationMediator;
	
	
	

	public class StartupCommand extends BaseCommand
	{
		override public function execute(notification:INotification):void {
			super.execute(notification);
			
			var mainApp:Main = notification.getBody() as Main;
			
			var serverName:String = URLUtil.getServerName(mainApp.url);
			
			logger.info('Server name: ' + serverName);
			
			settingsProxy.isDev = true;
			
			//if (!mainApp.parameters.logger) Logger.flushAll();
			
			facade.registerMediator( new MainApplicationMediator(mainApp) );
			
			//app_context_path
			var app_context_path:String = mainApp.parameters.app_context_path ? 
											String(mainApp.parameters.app_context_path) : null;
			
			//if (app_context_path) this.settingsProxy.rootURL = app_context_path;
				
			
			//load config (settings.xml)
			var config_url:String = mainApp.parameters.config_url ? String(mainApp.parameters.config_url) : null;
			config_url = config_url ? config_url : 'settings.xml';
						
			facade.sendNotification(CoreNotifications.LOAD_CONFIG, config_url);
		}
		
	}
}